package com.management.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class CopyUtils {

    public static  <T>T CopyOne(Object resource,Class<T> clazz){
        T t = null;
        try {
            t = clazz.newInstance();
            BeanUtils.copyProperties(resource,t);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return t;
    }

    public static <T>List CopyList(List resource,Class<T> clazz){
        List<T> list =new ArrayList();
        try {
            for (Object obj : resource) {
               T t= clazz.newInstance();
                BeanUtils.copyProperties(obj,t);
                list.add(t);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return list;
    }

}
